<?php
/**
 * 点大商城（www.diandashop.com） - 微信公众号小程序商城系统!
 * Copyright © 2020 山东点大网络科技有限公司 保留所有权利
 * =========================================================
 * 版本：V2
 * 授权主体：shop.guanjunbang.cn
 * 授权域名：shop.guanjunbang.cn
 * 授权码：vdcajlVLIVAgVdkfJvgY
 * ----------------------------------------------
 * 您只能在商业授权范围内使用，不可二次转售、分发、分享、传播
 * 任何企业和个人不得对代码以任何目的任何形式的再发布
 * =========================================================
 */

namespace app\controller;
use think\facade\Db;
class ApiMoney extends ApiCommon
{
	public function initialize(){
		parent::initialize();
		$this->checklogin();
	}

	//余额充值
	public function recharge(){
		$canrecharge = Db::name('admin_set')->where('aid',aid)->value('recharge');
		$giveset = Db::name('recharge_giveset')->where('aid',aid)->find();
		if($giveset && $giveset['status']==1){
			$givedata = json_decode($giveset['givedata'],true);
		}else{
			$givedata = [];
		}
		if(request()->isPost()){
			if($canrecharge == 0) return $this->json(['status'=>0,'msg'=>t('余额').'充值功能未启用']);
			$money = input('post.money');
			if($money>0){
				$ordernum = date('ymdHis').aid.rand(1000,9999);
				//增加消费记录
				$orderdata = [];
				$orderdata['aid'] = aid;
				$orderdata['mid'] = mid;
				$orderdata['createtime']= time();
				$orderdata['money'] = $money;
				$orderdata['ordernum'] = $ordernum;
				$orderid = Db::name('recharge_order')->insertGetId($orderdata);
				$payorderid = \app\model\Payorder::createorder(aid,0,$orderdata['mid'],'recharge',$orderid,$ordernum,t('余额').'充值',$money);

				return $this->json(['status'=>1,'msg'=>'提交成功','orderid'=>$orderid,'payorderid'=>$payorderid]);
			}else{
				return $this->json(['status'=>0,'msg'=>'充值金额必须大于0']);
			}
		}
		$userinfo = [];
		$userinfo['money'] = $this->member['money'];
		$set = Db::name('admin_set')->where('aid',aid)->find();
		$rdata = [];
		$rdata['canrecharge'] = $canrecharge;
		$rdata['giveset'] = $givedata;
		$rdata['shuoming'] = $giveset['shuoming'];
		$rdata['caninput'] = $giveset ? $giveset['caninput'] : 1;
		$rdata['userinfo'] = $userinfo;
		$rdata['transfer'] = $set['money_transfer'] ? true : false;
		return $this->json($rdata);
	}

    public function rechargeToMember()
    {
        }
}